package com.graduation.apiservice.controller;

import com.graduation.common.utils.UserContext;
import com.graduation.pojo.po.SearchHistory;
import com.graduation.service.SearchHistoryService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/searchHistory")
@RequiredArgsConstructor
public class SearchHistoryController {

    private final SearchHistoryService searchHistoryService;

    /**
     * 获取当前用户的搜索记录（前20条）
     */
    @GetMapping("/list")
    public List<SearchHistory> getSearchHistory() {
        Long userId = UserContext.getUser();
        return searchHistoryService.getUserSearchHistory(userId);
    }

    /**
     * 添加搜索记录
     */
    @PostMapping("/add")
    public void addSearchHistory(String query) {
        Long userId = UserContext.getUser();
        searchHistoryService.addSearchHistory(userId, query);
    }

}
